package com.orangelife.webservice.service.propFeeLinkBillType.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.core.Response;

import org.springframework.stereotype.Service;

import com.github.pagehelper.Page;
import com.orangelife.controller.AuthPermissionApp;
import com.orangelife.service.linkBillType.IPropFeeLinkBillTypeService;
import com.orangelife.service.linkBillType.modal.PropFeeLinkBillTypeDto;
import com.orangelife.setting.constant.CodeConst;
import com.orangelife.setting.constant.InfoConst;
import com.orangelife.utils.PropertyUtils;
import com.orangelife.utils.StringUtils;
import com.orangelife.webservice.base.BaseService;
import com.orangelife.webservice.service.propFeeLinkBillType.IPropFeeLinkBillTypeWebService;
/*****************************************************************
 * Copyright(C) ORANGELIFE Corporation 2015. All Rights Reserved.
 *****************************************************************/
/* ==============================================================
 * 功能名                       propFeeLinkBillType类 的WebService基本作业
 * @author         zhr
 * @version         1.1.0
 * @date             2016-07-04 13:54:37
 * ==============================================================*/
@Service("webservice_propFeeLinkBillType")
public class  PropFeeLinkBillTypeWebServiceImpl extends BaseService implements
		IPropFeeLinkBillTypeWebService {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;


	@Resource(name = "propFeeLinkBillTypeService")
	private IPropFeeLinkBillTypeService propFeeLinkBillTypeService;

	

	@Override

	public Response addPropFeeLinkBillType(HttpServletRequest servletRequest, PropFeeLinkBillTypeDto propFeeLinkBillType)
			throws Exception {

			/************************************************
			 * 检查session
			 ************************************************/
			//PageUtils pageUtils=this.validateLogin(servletRequest, "web");
		
			int result = propFeeLinkBillTypeService.addPropFeeLinkBillType(propFeeLinkBillType);
			if(!(result>0)){
			return this.abnormalResp(CodeConst.BIS_CODE_13006,
					InfoConst.BIS_INFO_13006);
			}


			return this.normalResp();
	}

	@Override

	public Response editPropFeeLinkBillType(HttpServletRequest servletRequest, PropFeeLinkBillTypeDto propFeeLinkBillType)
			throws Exception {
             /************************************************
			 * 检查session
			 ************************************************/
			//PageUtils pageUtils=this.validateLogin(servletRequest, "web");
		
		
			/************************************************
			 * 输入参数ID检查
			 ************************************************/
			Response error = this.validateUUId(
					propFeeLinkBillType.getLinkID(), "linkID");
			if (error != null) {
				return error;
			}
			
			/************************************************
			 * 输入参数检查
			 ************************************************/
			//TODO;
			
			int result = propFeeLinkBillTypeService.editPropFeeLinkBillType(propFeeLinkBillType);
			if(!(result>0)){
			return this.abnormalResp(CodeConst.BIS_CODE_13006,
					InfoConst.BIS_INFO_13006);
			}
		

			return this.normalResp();
	}

	@Override

	public Response deletePropFeeLinkBillType(HttpServletRequest servletRequest, String linkID)
			throws Exception {
             /************************************************
			 * 检查session
			 ************************************************/

	
			/************************************************
			 * 输入参数ID检查
			 ************************************************/
			Response error = this.validateUUId(linkID, "linkID");
			if (error != null) {
				return error;
			}
			int result = propFeeLinkBillTypeService.deletePropFeeLinkBillTypeByLogic(linkID);
			if(!(result>0)){
			return this.abnormalResp(CodeConst.BIS_CODE_13006,
					InfoConst.BIS_INFO_13006);
		}
	

			return this.normalResp();
	}

	@Override
	public Response findPropFeeLinkBillTypeByID(HttpServletRequest servletRequest, String linkID)
			throws Exception {

             /************************************************
			 * 检查session
			 ************************************************/
		
		
			/************************************************
			 * 输入参数ID检查
			 ************************************************/
			Response error = this.validateUUId(linkID, "linkID");
			if (error != null) {
				return error;
			}
			PropFeeLinkBillTypeDto propFeeLinkBillType = propFeeLinkBillTypeService.findPropFeeLinkBillTypeByID(linkID);

			Map<String, Object> maps = new HashMap<String, Object>();

			if (propFeeLinkBillType != null) {
				
			}


			return this.normalResp(propFeeLinkBillType);
	}
	
	@Override
	@AuthPermissionApp
	public Response getAllPropFeeLinkBillType(HttpServletRequest servletRequest,String search,  String commID,
			String pageIndex, String pageSize) throws Exception {

		 int pageIndex1=1;
		 int pageSize1=10;
   if(!StringUtils.isBlank(pageSize)){
	   pageSize1=Integer.parseInt(pageSize);
			
		}
		
		if(!StringUtils.isBlank(pageIndex)){
			
			pageIndex1=Integer.parseInt(pageIndex);
		}
			
		
			/************************************************
			 * 查询列表
			 ************************************************/
			List<Map<String, Object>> list = propFeeLinkBillTypeService.findPropFeeLinkBillTypeByPage(commID==null?null:commID,
					search == null ? null : search, pageIndex1,pageSize1);
			
			/************************************************
			 * 返回结果设定
			 ************************************************/
			Long total = ((Page<Map<String, Object>>) list).getTotal();


			return this.normalResp(pageIndex1, pageSize1, total, PropertyUtils.turnToEntity(list));
	}



	@Override
	public Response getBillType(HttpServletRequest servletRequest,
			String commID, String pageIndex, String pageSize) throws Exception {
		
		 int pageIndex1=1;
		 int pageSize1=2000;
  if(!StringUtils.isBlank(pageSize)){
	   pageSize1=Integer.parseInt(pageSize);
			
		}
		
		if(!StringUtils.isBlank(pageIndex)){
			
			pageIndex1=Integer.parseInt(pageIndex);
		}
			
		/************************************************
		 * 查询列表
		 ************************************************/
		List<Map<String, Object>> list = propFeeLinkBillTypeService.findBillType(commID==null?null:commID,null,
		 pageIndex1,pageSize1);
		
		/************************************************
		 * 返回结果设定
		 ************************************************/
		Long total = ((Page<Map<String, Object>>) list).getTotal();


		return this.normalResp(pageIndex1, pageSize1, total, PropertyUtils.turnToEntity(list));
	}

	@Override
	public Response getFeeType(HttpServletRequest servletRequest,
			String commID, String pageIndex, String pageSize) throws Exception {
		 int pageIndex1=1;
		 int pageSize1=2000;
  if(!StringUtils.isBlank(pageSize)){
	   pageSize1=Integer.parseInt(pageSize);
			
		}
		
		if(!StringUtils.isBlank(pageIndex)){
			
			pageIndex1=Integer.parseInt(pageIndex);
		}
			
		/************************************************
		 * 查询列表
		 ************************************************/
		List<Map<String, Object>> list = propFeeLinkBillTypeService.findFeeType(commID==null?null:commID,null,
		 pageIndex1,pageSize1);
		
		/************************************************
		 * 返回结果设定
		 ************************************************/
		Long total = ((Page<Map<String, Object>>) list).getTotal();


		return this.normalResp(pageIndex1, pageSize1, total, PropertyUtils.turnToEntity(list));
	}

	
}
